/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package draw;

import model.MaterialDirection;

import java.awt.Color;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.Shape;
import java.awt.geom.AffineTransform;
import java.awt.geom.Line2D;
import java.awt.geom.Path2D;
import java.awt.geom.Rectangle2D;

/**
 *
 * @author Ahmet
 */
public class pnlExample extends javax.swing.JPanel {

    private ColorSet set;
    private double theta;
    private MaterialDirection soort;
    
    /**
     * Creates new form pnlExample2
     */
    public pnlExample() {
        initComponents();
        set = new ColorSet(Color.white, Color.red);
        theta = 0;
        soort = MaterialDirection.MINVIJFENVEERTIGVIJFENVEERTIG;
    }

    public pnlExample(ColorSet set) {
        initComponents();
        this.set=set;
    }
    
    

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        setMaximumSize(new java.awt.Dimension(50, 20));
        setMinimumSize(new java.awt.Dimension(50, 20));
        setPreferredSize(new java.awt.Dimension(50, 20));

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
        this.setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 50, Short.MAX_VALUE)
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 20, Short.MAX_VALUE)
        );
    }// </editor-fold>//GEN-END:initComponents
    // Variables declaration - do not modify//GEN-BEGIN:variables
    // End of variables declaration//GEN-END:variables

public static Shape rotateShape(final Shape base, final double angle,
                                  final float x, final float y) {
      if (base == null) {
          return null;
      }
      final AffineTransform rotate = AffineTransform.getRotateInstance(
              angle, x, y);
      final Shape result = rotate.createTransformedShape(base);
      return result;
  }

    @Override
    public void paint(Graphics g)
    {
        super.paint(g);
        Graphics2D g2 = (Graphics2D) g;
        g2.setColor(set.getBackground());
        Rectangle2D rect = new Rectangle2D.Double(0, 0, 49, 19);
        g2.fill(rect);
        g2.setColor(Color.black);
        g2.draw(rect);
        g2.setColor(set.getFiber());
        
        if(soort.equals(MaterialDirection.UNIDIRECTIONAAL))
        {
            Line2D line1 = new java.awt.geom.Line2D.Double(-10, 2, 60, 2);
            Path2D lijn1 = (Path2D) rotateShape(line1, Math.toRadians(theta), 5, 2);
            Line2D line2 = new java.awt.geom.Line2D.Double(-10, 6, 60, 6);
            Path2D lijn2 = (Path2D) rotateShape(line2, Math.toRadians(theta), 15, 6);
            Line2D line3 = new java.awt.geom.Line2D.Double(-10, 10, 60, 10);
            Path2D lijn3 = (Path2D) rotateShape(line3, Math.toRadians(theta), 25, 10);
            Line2D line4 = new java.awt.geom.Line2D.Double(-10, 14, 60, 14);
            Path2D lijn4 = (Path2D) rotateShape(line4, Math.toRadians(theta), 35, 14);
            Line2D line5 = new java.awt.geom.Line2D.Double(-10, 18, 60, 18);
            Path2D lijn5 = (Path2D) rotateShape(line5, Math.toRadians(theta), 45, 18);

            if(theta>0)
            {

                lijn1 = (Path2D) rotateShape(line1, Math.toRadians(theta), 45, 2);

                lijn2 = (Path2D) rotateShape(line2, Math.toRadians(theta), 35, 6);

                lijn3 = (Path2D) rotateShape(line3, Math.toRadians(theta), 25, 10);

                lijn4 = (Path2D) rotateShape(line4, Math.toRadians(theta), 15, 14);

                lijn5 = (Path2D) rotateShape(line5, Math.toRadians(theta), 5, 18);
            }

            Rectangle2D rectclip = new Rectangle2D.Double(2, 2, 45, 15);


            g2.clip(rectclip);
            g2.draw(lijn1);
            g2.draw(lijn2);
            g2.draw(lijn3);
            g2.draw(lijn4);
            g2.draw(lijn5);
        }
        else if(soort.equals(MaterialDirection.NULNEGENTIG))
        {

            Line2D line1 = new java.awt.geom.Line2D.Double(-10, 2, 60, 2);
            Path2D lijn1 = (Path2D) rotateShape(line1, Math.toRadians(theta), 5, 2);
            Line2D line2 = new java.awt.geom.Line2D.Double(-10, 6, 60, 6);
            Path2D lijn2 = (Path2D) rotateShape(line2, Math.toRadians(theta), 15, 6);
            Line2D line3 = new java.awt.geom.Line2D.Double(-10, 10, 60, 10);
            Path2D lijn3 = (Path2D) rotateShape(line3, Math.toRadians(theta), 25, 10);
            Line2D line4 = new java.awt.geom.Line2D.Double(-10, 14, 60, 14);
            Path2D lijn4 = (Path2D) rotateShape(line4, Math.toRadians(theta), 35, 14);
            Line2D line5 = new java.awt.geom.Line2D.Double(-10, 18, 60, 18);
            Path2D lijn5 = (Path2D) rotateShape(line5, Math.toRadians(theta), 45, 18);

            if(theta>0)
            {

                lijn1 = (Path2D) rotateShape(line1, Math.toRadians(theta), 45, 2);

                lijn2 = (Path2D) rotateShape(line2, Math.toRadians(theta), 35, 6);

                lijn3 = (Path2D) rotateShape(line3, Math.toRadians(theta), 25, 10);

                lijn4 = (Path2D) rotateShape(line4, Math.toRadians(theta), 15, 14);

                lijn5 = (Path2D) rotateShape(line5, Math.toRadians(theta), 5, 18);
            }

            Rectangle2D rectclip = new Rectangle2D.Double(2, 2, 45, 15);


            if(theta<0)
            {
                theta += 90;
            }
            else
            {
                theta -= 90;
            }

            Line2D line6 = new java.awt.geom.Line2D.Double(-10, 2, 60, 2);
            Path2D lijn6 = (Path2D) rotateShape(line1, Math.toRadians(theta), 5, 2);
            Line2D line7 = new java.awt.geom.Line2D.Double(-10, 6, 60, 6);
            Path2D lijn7 = (Path2D) rotateShape(line2, Math.toRadians(theta), 15, 6);
            Line2D line8 = new java.awt.geom.Line2D.Double(-10, 10, 60, 10);
            Path2D lijn8 = (Path2D) rotateShape(line3, Math.toRadians(theta), 25, 10);
            Line2D line9 = new java.awt.geom.Line2D.Double(-10, 14, 60, 14);
            Path2D lijn9 = (Path2D) rotateShape(line4, Math.toRadians(theta), 35, 14);
            Line2D line10 = new java.awt.geom.Line2D.Double(-10, 18, 60, 18);
            Path2D lijn10 = (Path2D) rotateShape(line5, Math.toRadians(theta), 45, 18);

            if(theta>0)
            {

                lijn6 = (Path2D) rotateShape(line6, Math.toRadians(theta), 45, 2);

                lijn7 = (Path2D) rotateShape(line7, Math.toRadians(theta), 35, 6);

                lijn8 = (Path2D) rotateShape(line8, Math.toRadians(theta), 25, 10);

                lijn9 = (Path2D) rotateShape(line9, Math.toRadians(theta), 15, 14);

                lijn10 = (Path2D) rotateShape(line10, Math.toRadians(theta), 5, 18);
            }




            g2.clip(rectclip);
            g2.draw(lijn1);
            g2.draw(lijn2);
            g2.draw(lijn3);
            g2.draw(lijn4);
            g2.draw(lijn5);
            g2.draw(lijn6);
            g2.draw(lijn7);
            g2.draw(lijn8);
            g2.draw(lijn9);
            g2.draw(lijn10);
        }
        else if(soort.equals(MaterialDirection.MINVIJFENVEERTIGVIJFENVEERTIG))
        {
            if(theta<0)
            {
                theta += 45;
            }
            else
            {
                theta -= 45;
            }

            Line2D line1 = new java.awt.geom.Line2D.Double(-10, 2, 60, 2);
            Path2D lijn1 = (Path2D) rotateShape(line1, Math.toRadians(theta), 5, 2);
            Line2D line2 = new java.awt.geom.Line2D.Double(-10, 6, 60, 6);
            Path2D lijn2 = (Path2D) rotateShape(line2, Math.toRadians(theta), 15, 6);
            Line2D line3 = new java.awt.geom.Line2D.Double(-10, 10, 60, 10);
            Path2D lijn3 = (Path2D) rotateShape(line3, Math.toRadians(theta), 25, 10);
            Line2D line4 = new java.awt.geom.Line2D.Double(-10, 14, 60, 14);
            Path2D lijn4 = (Path2D) rotateShape(line4, Math.toRadians(theta), 35, 14);
            Line2D line5 = new java.awt.geom.Line2D.Double(-10, 18, 60, 18);
            Path2D lijn5 = (Path2D) rotateShape(line5, Math.toRadians(theta), 45, 18);

            if(theta>0)
            {

                lijn1 = (Path2D) rotateShape(line1, Math.toRadians(theta), 45, 2);

                lijn2 = (Path2D) rotateShape(line2, Math.toRadians(theta), 35, 6);

                lijn3 = (Path2D) rotateShape(line3, Math.toRadians(theta), 25, 10);

                lijn4 = (Path2D) rotateShape(line4, Math.toRadians(theta), 15, 14);

                lijn5 = (Path2D) rotateShape(line5, Math.toRadians(theta), 5, 18);
            }

            Rectangle2D rectclip = new Rectangle2D.Double(2, 2, 45, 15);


            if(theta<0)
            {
                theta += 90;
            }
            else
            {
                theta -= 90;
            }

            Line2D line6 = new java.awt.geom.Line2D.Double(-10, 2, 60, 2);
            Path2D lijn6 = (Path2D) rotateShape(line1, Math.toRadians(theta), 5, 2);
            Line2D line7 = new java.awt.geom.Line2D.Double(-10, 6, 60, 6);
            Path2D lijn7 = (Path2D) rotateShape(line2, Math.toRadians(theta), 15, 6);
            Line2D line8 = new java.awt.geom.Line2D.Double(-10, 10, 60, 10);
            Path2D lijn8 = (Path2D) rotateShape(line3, Math.toRadians(theta), 25, 10);
            Line2D line9 = new java.awt.geom.Line2D.Double(-10, 14, 60, 14);
            Path2D lijn9 = (Path2D) rotateShape(line4, Math.toRadians(theta), 35, 14);
            Line2D line10 = new java.awt.geom.Line2D.Double(-10, 18, 60, 18);
            Path2D lijn10 = (Path2D) rotateShape(line5, Math.toRadians(theta), 45, 18);

            if(theta>0)
            {

                lijn6 = (Path2D) rotateShape(line6, Math.toRadians(theta), 45, 2);

                lijn7 = (Path2D) rotateShape(line7, Math.toRadians(theta), 35, 6);

                lijn8 = (Path2D) rotateShape(line8, Math.toRadians(theta), 25, 10);

                lijn9 = (Path2D) rotateShape(line9, Math.toRadians(theta), 15, 14);

                lijn10 = (Path2D) rotateShape(line10, Math.toRadians(theta), 5, 18);
            }




            g2.clip(rectclip);
            g2.draw(lijn1);
            g2.draw(lijn2);
            g2.draw(lijn3);
            g2.draw(lijn4);
            g2.draw(lijn5);
            g2.draw(lijn6);
            g2.draw(lijn7);
            g2.draw(lijn8);
            g2.draw(lijn9);
            g2.draw(lijn10);
        }

        



        
        //g2.draw(rectclip);
        
        
    }

    public ColorSet getSet() {
        return set;
    }

    public void setSet(ColorSet set) {
        this.set = set;
        this.repaint();
    }

    public double getTheta() {
        return theta;
    }

    public void setTheta(double theta) {
        this.theta = theta;
        this.repaint();
    }

    public void setSoort(MaterialDirection soort)
    {
        this.soort = soort;
        this.repaint();
    }
}
